import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_study/mvvm/model/storymodel.dart';
import 'package:flutter_study/mvvm/model/storymodellist.dart';

abstract class StoryListViewModelImpl {
  depose();
}

class StoryListViewModel implements StoryListViewModelImpl {
  List<StoryModel> storyList = List();
  var _storyListController = StreamController<StoryModel>.broadcast();

  Sink get inStoryListController => _storyListController;

  Stream<List<StoryModel>> get outStoryListz =>
      _storyListController.stream.map((story) {
        storyList.add(story);
        return storyList;
      });

  addData() async {
    storyList.clear();
    for (int i = 0; i < 10; i++) {
      StoryModel storyModel = StoryModel(id: '第${i}个', title: '这里内容是${i}');
      inStoryListController.add(storyModel);
    }
  }

  depose() {
    _storyListController.close();
  }
}
